class Solution {
    public int[] searchRange(int[] nums, int target) {
        int[] ans = {-1, -1};
        if (nums.length == 0) {
            return ans;
        }

        int start = searchRange1(nums, target);
        int end = searchRange2(nums, target);
        if (( 0 <= start && start <= nums.length -1 ) && nums[start] == target) {
            ans[0] = start;
            ans[1] = end -1;
        }
        return ans;
    }

    // <= value
    public int searchRange1(int[] nums, int target) {
        int start = 0, end = nums.length -1;
        while (start <= end) {
            int mid = (start + end) >>> 1;
            int midValue = nums[mid];
            if (target <= midValue) {
                end = mid - 1;
            } else {
                start = mid + 1;
            }
        }
        return start;
    }

	// > target
    public int searchRange2(int[] nums, int target) {
        int start = 0, end = nums.length -1;
        while (start <= end) {
            int mid = (start + end) >>> 1;
            int midValue = nums[mid];
            if (target < midValue) {
                end = mid - 1;
            } else {
                start = mid + 1;
            }
        }
        return start;
    }
}